//
//  UIBarButtonItem+Extension.m
//  HonlivApp
//
//  Created by admin on 2017/6/23.
//  Copyright © 2017年 honliv. All rights reserved.
//

#import "UIBarButtonItem+Extension.h"

@implementation UIBarButtonItem (Extension)

+(instancetype)initWithTitle:(NSString *)title fontSize:(CGFloat)size target:(NSObject *)target action:(SEL)select isBack:(BOOL)isBack{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(0, 0, 44, 44);
    btn.titleLabel.font = kFont(size);
    [btn setTitle:title forState:UIControlStateNormal];
    if (isBack) {
        UIImage *image = [UIImage imageNamed:@"back.png"];
        UIImage *selectImg = [UIImage imageNamed:@"back_H.png"];
        [btn setImage:image forState:UIControlStateNormal];
        [btn setImage:selectImg forState:UIControlStateHighlighted];
        [btn setImageEdgeInsets:UIEdgeInsetsMake(0, -10, 0, 10)];
        [btn setTitleEdgeInsets:UIEdgeInsetsMake(0, -15, 0, 15)];
        [btn sizeToFit];
    }
    else{
        [btn setTitleEdgeInsets:UIEdgeInsetsMake(0, -20, 0, 20)];
    }
    [btn addTarget:target action:select forControlEvents:UIControlEventTouchUpInside];
    
    return [[self alloc] initWithCustomView:btn];
    
}

@end
